#include <modules\graphics\model_pose.h>

namespace DelGE
{
	namespace Modules
	{
		namespace Graphics
		{
			ModelPose::ModelPose(Mesh* pPoseMesh)
			{
				this->vVertexPositions = vector<Vector3>();
				this->vVertexNormals = vector<Vector3>();

				for (int iVertexIndex = 0; iVertexIndex < pPoseMesh->GetVertexCount(); iVertexIndex ++)
				{
					Vertex* pVertex = pPoseMesh->GetVertex(iVertexIndex);

					Vector3 vertextPosition = Vector3(0, 0, 0);
					Vector3 vertextNormal = Vector3(0, 0, 0);
					if (pVertex != NULL)
					{
						vertextPosition[0] = pVertex->position[0];
						vertextPosition[1] = pVertex->position[1];
						vertextPosition[2] = pVertex->position[2];
						
						vertextNormal[0] = pVertex->normal[0];
						vertextNormal[1] = pVertex->normal[1];
						vertextNormal[2] = pVertex->normal[2];
					}

					this->vVertexPositions.push_back(vertextPosition);
					this->vVertexNormals.push_back(vertextNormal);
				}
			}

			ModelPose::ModelPose(ModelPose* pModelPose)
			{
				this->vVertexPositions = vector<Vector3>();

				for (int iVertexIndex = 0; iVertexIndex < pModelPose->GetVertexCount(); iVertexIndex ++)
				{
					this->vVertexPositions.push_back(pModelPose->GetVertexPosition(iVertexIndex));
					this->vVertexNormals.push_back(pModelPose->GetVertexNormal(iVertexIndex));
				}
			}

			ModelPose::~ModelPose()
			{
				this->vVertexPositions.clear();
			}

			void ModelPose::SetVertexPosition(int iIndex, const Vector3& rVertexPosition)
			{
				if (this->vVertexPositions.empty() || iIndex < 0 || iIndex >= this->GetVertexCount()) return;

				this->vVertexPositions[iIndex] = rVertexPosition;
			}

			Vector3 ModelPose::GetVertexPosition(int iIndex)
			{
				if (this->vVertexPositions.empty() || iIndex < 0 || iIndex >= this->GetVertexCount()) return Vector3(-1, -1, -1);

				return this->vVertexPositions[iIndex];
			}

			int ModelPose::GetVertexCount()
			{
				return this->vVertexPositions.size();
			}

			void ModelPose::SetVertexNormal(int iIndex, const Vector3& rVertexNormal)
			{
				if (this->vVertexNormals.empty() || iIndex < 0 || iIndex >= this->GetVertexCount()) return;

				this->vVertexNormals[iIndex] = rVertexNormal;
			}

			Vector3 ModelPose::GetVertexNormal(int iIndex)
			{
				if (this->vVertexNormals.empty() || iIndex < 0 || iIndex >= this->GetVertexCount()) return Vector3(-1, -1, -1);

				return this->vVertexNormals[iIndex];
			}
		}
	}
}